package com.situ.mall.shopping.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.shopping.model.ShoppingModel;
import com.situ.mall.shopping.service.impl.ShoppingServiceImpl;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("mall")
public class ShoppingController {

	@Autowired
	private ShoppingServiceImpl shoppingServiceImpl;
	
	@RequestMapping(value = "/list" ,produces = {"application/json;charset=UTF-8"} ,method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public List<ShoppingModel> list(ShoppingModel model){
		List<ShoppingModel> res = shoppingServiceImpl.selectList(model);
		res = JSONArray.fromObject(res);
		System.out.println("res="+res);
		return res;
	}
	
	@RequestMapping(value = "/add",produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public int add(ShoppingModel model) {
		int res = shoppingServiceImpl.insert(model);
		System.out.println("res="+res);
		return res;
	}
	
	@RequestMapping(value = "/del",produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public int del(ShoppingModel model) {
		int res = shoppingServiceImpl.delete(model);
		System.out.println("res="+res);
		return res;
	}
	
	@RequestMapping(value = "/upd",produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public int upd(ShoppingModel model) {
		int res = shoppingServiceImpl.update(model);
		System.out.println("res="+res);
		return res;
	}
}
